<template>
    <el-row :gutter="20">
        <el-col :span="13">
            <el-alert title="客户疗程卡里有效项目列表" type="success" class="mt"></el-alert>
            <el-table :data="clist" height="500" @row-click="sele">
                <el-table-column label="选择">
                    <template slot-scope="scope">
                        <el-checkbox v-model="scope.row.selected"></el-checkbox>
                    </template>
                </el-table-column>
                <el-table-column type="index" label="#"></el-table-column>
                <el-table-column prop="name" label="项目"></el-table-column>
                <el-table-column prop="price" label="标准价"></el-table-column>
                <el-table-column prop="disprice" label="折扣价"></el-table-column>
                <el-table-column prop="num" label="总数"></el-table-column>
                <el-table-column prop="nownum" label="剩余数"></el-table-column>
            </el-table>
        </el-col>
        <el-col :span="11">
            <el-alert title="客户有效期内期卡列表" type="success" class="mt"></el-alert>
            <el-table :data="qlist" height="500" @row-click="sele">
                <el-table-column label="选择">
                    <template slot-scope="scope">
                        <el-checkbox v-model="scope.row.selected"></el-checkbox>
                    </template>
                </el-table-column>
                <el-table-column type="index" label="#"></el-table-column>
                <el-table-column prop="name" label="卡名">
                    <template slot-scope="scope">
                        <span v-if="scope.row.name">{{scope.row.name}}</span>
                        <span v-else>无卡名</span>
                    </template>
                </el-table-column>
                <el-table-column prop="price" label="卡价">
                    <template slot-scope="scope">
                        <span v-if="scope.row.price">{{scope.row.price}}</span>
                        <span v-else>无卡价</span>
                    </template>
                </el-table-column>
                <el-table-column prop="geshu" label="项目数"></el-table-column>
                <el-table-column prop="endtime" label="有效期">
                    <template slot-scope="scope">
                        <span>{{times(scope.row.endtime)}}</span>
                    </template>
                </el-table-column>
            </el-table>
        </el-col>
        <el-col :span="24" class="right mt">
            <el-button type="primary" icon="el-icon-check" @click="submit">确定选择</el-button>
            <el-button type="danger" icon="el-icon-close" @click="close">取消关闭</el-button>
        </el-col>
    </el-row>
</template>
<script>
import C from '@/common/common.js'

export default {
  name: 'selectGuestCard',
  data () {
    return {
      clist: [],
      qlist: [],
      rmclist: [],
      rmqlist: [],
      selectrow: {},
      aaa: []
    }
  },
  methods: {
    submit: function () {
      if (!this.rmclist.length && !this.rmqlist.length) {
        C.error('请选择要退的卡项')
        return false
      }

      let retlist = {
        rcs: this.rmclist,
        rqs: this.rmqlist
      }
      C.closeBrowserWindow(retlist)
    },
    sele: function (row, event, column) {
      if (row.category === 2) {
        event.preventDefault()
        this.selectrow = row
        this.checkselect(this.clist, 2)
      } else {
        event.preventDefault()
        this.selectrow = row
        this.checkselect(this.qlist)
      }
    },
    checkselect: function (data, num) {
      // 如果没有就选中，有就取消选中
      if (this.aaa.indexOf(this.selectrow.id) === -1) {
        this.aaa.push(this.selectrow.id)
        if (num) {
          this.rmclist.push(this.selectrow)
        } else {
          this.rmqlist.push(this.selectrow)
        }
        data.forEach((row, index) => {
          if (row.id === this.selectrow.id) {
            data[index].selected = true
          }
        })
      } else {
        this.aaa.splice(this.aaa.indexOf(this.selectrow.id), 1)
        if (num) {
          this.rmclist.splice(this.aaa.indexOf(this.selectrow.id), 1)
        } else {
          this.rmqlist.splice(this.aaa.indexOf(this.selectrow.id), 1)
        }
        data.forEach((row, index) => {
          if (row.id === this.selectrow.id) {
            data[index].selected = false
          }
        })
      }
    },
    cardlist: async function (gid) {
      let res = await C.ajax('/shop/backcard/guestcardlist', { id: gid })
      if (res) {
        res.clist.forEach((v) => {
          v.selected = false
          v.category = 2
        })
        res.qlist.forEach((v) => {
          v.selected = false
          v.category = 1
        })
        this.clist = res.clist
        this.qlist = res.qlist
      }
    },
    times: function (unix) {
      return C.time(unix)
    },
    close () {
      C.closewin()
    }
  },
  mounted: function () {
    let gid = C.getDatas().gid
    this.cardlist(gid)
  }
}
</script>
<style>
.ov {
    overflow: hidden;
}

.ov-x {
    overflow-x: hidden;
}

.fl {
    float: left;
}

.fr {
    float: right;
}

.clear {
    clear: both;
}

.none {
    display: none;
}

.block {
    display: block;
}

.handel {
    cursor: pointer;
}



/*背景颜色-前景颜色*/

.bg-dark {
    background: #F9FAFC;
}

.bg-extra {
    background: #EFF2F7;
}

.bg-light {
    background: #E5E9F2;
}

.bg-gray {
    background: #D3DCE6;
}

.bg-silver {
    background: #8492A6;
}

.bg-black {
    background: #324057;
}

.white {
    color: white;
}

.black {
    color: #324057;
}

.green {
    color: green;
}

.blue {
    color: blue;
}

.red {
    color: red;
}

.color-nan {
    color: #2a91f7;
}

.color-nv {
    color: #f7992a;
}



/*其他样式*/

html {
    font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, SimSun, sans-serif;
    font-weight: 400;
}

.title {
    font-size: 16px;
    font-family: "Helvetica Neue", "Helvetica", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
    line-height: 26px;
    margin: 10px 0;
}

.border {
    border: 1px solid #dfe6ec;
    border-radius: 4px;
    padding: 0 8px;
}

.bd {
    border: 1px solid #dfe6ec;
}

.border-b {
    border-bottom: 1px solid #dfe6ec;
}

.border-t {
    border-top: 1px solid #dfe6ec;
}

.bd-l {
    border-left: 1px dashed #dfe6ec;
}

.bd-t {
    border-top: 1px dashed #dfe6ec;
}

.bd-r {
    border-radius: 50%;
}

.underline {
    text-decoration: underline;
}



/*边距*/

.p0 {
    padding: 0 !important;
}

.m0 {
    margin: 0 !important;
}

.m10 {
    margin: 10px !important;
}

.m15 {
    margin: 15px !important;
}

.p10 {
    padding: 10px !important;
}

.p15 {
    padding: 15px !important;
}

.ml {
    margin-left: 15px !important;
}

.mr {
    margin-right: 15px !important;
}

.mb {
    margin-bottom: 15px !important;
}

.mt {
    margin-top: 15px !important;
}

.pl {
    padding-left: 15px !important;
}

.pl0 {
    padding-left: 0 !important;
}

.pr {
    padding-right: 15px !important;
}

.pr0 {
    padding-right: 0 !important;
}

.pb {
    padding-bottom: 15px !important;
}

.pt {
    padding-top: 15px !important;
}

.center {
    text-align: center !important;
}

.left {
    text-align: left !important;
}

.right {
    text-align: right !important;
}

.w100 {
    width: 100px !important;
}

.w150 {
    width: 150px !important;
}

.w200 {
    width: 200px !important;
}

.w300 {
    width: 300px !important;
}

.w400 {
    width: 400px !important;
}

.w500 {
    width: 500px !important;
}

.w30 {
    width: 30%;
}

.w50 {
    width: 50%;
}

.width95 {
    width: 95%;
}

.width {
    width: 100% !important;
}

.h200 {
    height: 200px;
}

.h300 {
    height: 300px;
}

.h500 {
    height: 500px;
}

.h600 {
    height: 600px;
}

.h700 {
    height: 700px;
}

.h800 {
    height: 800px;
}

.l28 {
    line-height: 28px;
}

.l30 {
    line-height: 30px;
}

.l50 {
    line-height: 50px;
}



/*附加订制样式*/

.el-row {
    margin: 0 !important;
}

.el-table .cell {
    padding: 0;
    text-align: center;
}

.el-textarea__inner {
    resize: none;
}

.el-input.is-disabled .el-input__inner {
    color: #20A0FF;
}

.el-textarea.is-disabled .el-textarea__inner {
    color: #444;
}

.el-switch {
    line-height: 0;
}

.el-checkbox+.el-checkbox {
    margin-left: 0;
}

.el-checkbox {
    margin-right: 20px;
}

.el-autocomplete-suggestion li {
    padding: 4px 20px;
    line-height: 20px;
}

.el-table th {
    padding: 10px 0;
}

.el-table td {
    padding: 4px 0;
}
</style>